//! # temperature_converter
//!
//! `temperature_converter`是温度转换器项目，支持摄氏和华氏互转。

pub struct Temperature {
    value: f64,
}

impl Temperature {
    /// Temperature实例化
    ///
    /// # Examples
    ///
    /// ```
    /// use temperature_converter::Temperature;
    /// let temp = Temperature::new(30.7);
    /// ```
    pub fn new(value: f64) -> Self {
        Self { value }
    }

    /// 摄氏转华氏
    ///
    /// # Examples
    ///
    /// ```
    /// use temperature_converter::Temperature;
    /// let temp = Temperature::new(30.7);
    /// // 30.7℃ = 87.26℉
    /// println!("30.7℃ = {:.2}℉", temp.celsius_to_fahrenheit());
    /// ```
    pub fn celsius_to_fahrenheit(&self) -> f64 {
        (self.value * 9.0 / 5.0) + 32.0
    }

    /// 华氏转摄氏
    ///
    /// # Examples
    ///
    /// ```
    /// use temperature_converter::Temperature;
    /// let temp = Temperature::new(87.26);
    /// // 87.26℉ = 30.70℃
    /// println!("87.26℉ = {:.2}℃", temp.fahrenheit_to_celsius());
    /// ```
    pub fn fahrenheit_to_celsius(&self) -> f64 {
        (self.value - 32.0) * 5.0 / 9.0
    }

    /// 获取`Temperature`结构体私有字段`value`的值
    pub fn value(&self) -> f64 {
        self.value
    }
}
